package com.example.demo.web;

import com.example.demo.util.Json;
import com.example.demo.util.UploadFile;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 * 图片上传
 * </p>
 * ***********************************************
 * BECAUSE OF CHOICE, STICK TO IT.               *
 * ***********************************************
 */
@Api(tags = "图片上传")
@RestController
@RequestMapping("imageUpload")
public class ImgUploadController {

    @ApiOperation("图片上载")
    @CrossOrigin(origins = "*", maxAge = 3600)
    @PostMapping("img_cache_upload.do")
    @ResponseBody
    public Json<Object> addImgCacheUpload(@RequestParam("picture") MultipartFile picture, HttpServletRequest request) {
        Map<String, String> file = UploadFile.uploadSingle(picture, request, "photocache/", false);
        return new Json<>(file.get("outputFile"));
    }


}
